package com.sinodata.bsm.cicp.finder.weblogic8;

import java.io.BufferedReader;
import java.io.IOException;

import org.apache.log4j.Logger;

import com.sinodata.bsm.cicp.util.CommandReader;

public class XmlGetter {

    private static final Logger logger = Logger.getLogger(XmlGetter.class);

    public static String getJmxXml(String key, String ip, String port, String username, String password) {
        String cmdStr = key + " " + ip + " " + port + " " + username + " " + password;
        BufferedReader reader = null;
        try {
            //			reader = com.union.pub.util.CollectorUtil
            //					.getReader(cmdStr, ip, 120);
            //reader = CmdServerPing.getReader(ip, cmdStr, 120, 0);
            reader = CommandReader.getReader(ip, cmdStr, 120, 0);
            StringBuffer stringBuffer = new StringBuffer();
            String line = null;
            while ((line = reader.readLine()) != null) {
                stringBuffer.append(line);
            }
            return stringBuffer.toString();
        } catch (Exception e) {
            logger.error(key + ":" + e);
            return null;
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException ex1) {
                    logger.error("failed to close reader", ex1);
                }
            }
        }
    }
}
